﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CPPEI.PM.Shell.SysViews
{
    /// <summary>
    /// Interaction logic for NavigationView.xaml
    /// </summary>
    public partial class NavigationView : UserControl
    {
        public NavigationView()
        {
            InitializeComponent();

            RefreshNavigation();
        }

        private void TreeViewItem_MouseDoubleClick_1(object sender, MouseButtonEventArgs e)
        {
            PMServiceRef.Navigation navigation = (sender as TreeViewItem).DataContext as PMServiceRef.Navigation;
            Event.UI.UIEventBus.Publish(new Event.UI.UIOpenWorkSheetEvent(navigation.WorkSheetId));
        }

        private void _ctlBtnRefresh_Click_1(object sender, RoutedEventArgs e)
        {
            RefreshNavigation();
        }

        private void RefreshNavigation()
        {
            _ctlTreeView.Items.Clear();
            PMServiceRef.Navigation[] navigationList = new PMServiceRef.PMWebServiceSoapClient().GetNavigationList(UIContext.Instance.Account, UIContext.Instance.Project.Id);
            //_ctlTreeView
            for (int index = 0; index < navigationList.Length; index++)
            {
                TreeViewItem treeViewItem = new TreeViewItem();
                treeViewItem.Header = navigationList[index].Caption;
                treeViewItem.DataContext = navigationList[index];
                treeViewItem.MouseDoubleClick += TreeViewItem_MouseDoubleClick_1;
                _ctlTreeView.Items.Add(treeViewItem);
            }
        }
    }
}
